<?php
require_once('../../config.php');
require_once('security.php');

	global $_POST;
    $cleanfiletitle = str_replace("-", "", $_POST['delete']);

    // Path to the menu.php file
    $filename = "../includes/menu.php";
	
	$teststr = 'php $' .$cleanfiletitle .' = new ';
	$found=0; // flag 
	$linesarray = file($filename);
    $fp = fopen($filename, "w") or die("Couldn't open $filename.");
	foreach($linesarray as $key => $line) {
		if ($found==1){
			if (trim($line) == "?>"){
				$found=0;
			}
		} else if (strpos($line,$teststr) != false  && $found==0){ // Found start of section to delete
			$found+=1;
		} else {
			fwrite($fp, $line);
		}
	}
	fclose($fp);
	
?>
